/**
 * 
 */
package SphericalHTM.client;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.logging.Logger;

/**
 * Jdbc access support class
 * @author Jun
 *
 */
public class JdbcSupportDAO {

	
	 protected Logger logger;
	 
	 protected ResourceBundle bundle = ResourceBundle.getBundle("mysql");
	 
	   public Connection getConnection()
	    {
		   
//	        String db_url = Configurer.getParameter("jdbcURL");
//	        String db_classname = Configurer.getParameter("dbDriver");
//	        String db_user = Configurer.getParameter("dbUser");
//	        String db_password = Configurer.getParameter("dbPwd");
	        
	       
	        String db_url = bundle.getString("jdbcURL");
	        String db_classname = bundle.getString("dbDriver");
	        String db_user = bundle.getString("dbUser");
	        String db_password = bundle.getString("dbPwd");
	        
	        try
	        {
	            Class.forName(db_classname);
	            Connection conn = DriverManager.getConnection(db_url, db_user, db_password);
	            return conn;
	        }
	        catch(Exception e)
	        {
	            logger.throwing(getClass().getName(), "getConnection", e);
	            throw new RuntimeException(e);
	        }
	    }
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		JdbcSupportDAO dao = new JdbcSupportDAO();
		dao.Query();
		

	}
	
	
	public void Query(){
		
		Connection conn = this.getConnection();
		String sql = "select  * from htmcode limit 5";
		
		try {
			
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				
				System.out.format("htmlcode:%s, longtitude :%s, latitude: %s \n",rs.getLong(1),rs.getLong(2),rs.getLong(3));
			}
			pstmt.close();
			conn.close();
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

	
}
